# -*- coding: iso-8859-1 -*-
#
#    This is part of Malvinas Argentinas Messenger
#
#    Malvinas Argentinas Messenger is free software; you can redistribute
#    it and/or modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2 of the
#    License, or (at your option) any later version.
#
#    Malvinas Argentinas Messenger is distributed in the hope that it will be
#    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Malvinas Argentinas Messenger; if not, write to the Free
#    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
#    MA  02110-1301  USA

class passList:
	def __init__(self):
		self.passports = []
		
	def append(self, item):
		self.passports.append(item)

	def size(self):
		return len(self.passports)

	def sizeNLN(self):
		i = 0
		for u in self.passports:
			if u.status not in ('FLN', 'HDN'):
				i += 1
		return i

	# Sort the list of passports
	def sortl(self):
		self.passports.sort(self.compare)

	# Function for sorting the list,
	# It compare status and names.
	def compare(self, x, y):
		self.prioridades = {"NLN" : "1", "BRB" : "2", "PHN" : "2", "LUN" : "2", "BSY" : "3", "AWY" : "4", "IDL" : "4", "HDN" : "5", "FLN" : "6"}
		res = -1
		if self.prioridades[x.status] > self.prioridades[y.status]:
			res = 1
		elif self.prioridades [x.status] == self.prioridades [y.status] and x.name > y.name:
			res = 1
		return res
	
	def numtoPass(self, num):
		#first in list is 0
		if (num < self.size()+1):
			return self.passports[num].name
		else:
			return ''
	
	def passinList(self, passp):
		ans = -1		
		for i in self.passports:
			if i.name == passp:
				ans = i
				break
		# Tocado
		#return ans
		return self.passports.index(ans)

	def countNonFLN(self):
		num = 0
		for i in self.passports:
			if i.status not in ('FLN', 'HDN'):
				num += 1
		return num

	def userStatus(self, user):
		res = ''
		for i in self.passports:
			if i.name == user:
				res = i.status
				break
		return res
